package com.thd.springboottest.springbootextends.customapplicationcontextinitializer;

import org.springframework.context.ApplicationContextInitializer;
import org.springframework.context.ConfigurableApplicationContext;
import org.springframework.core.env.ConfigurableEnvironment;

/**
 * com.thd.springboottest.springbootextends.customapplicationcontextinitializer.MyApplicationContextInitalizer
 *
 * @author: wanglei62
 * @DATE: 2022/4/22 14:21
 **/

/*
作用：
通常在需要对应用程序上下文进行一些编程初始化的web应用程序中使用。例如，根据上下文环境注册属性源或激活概要文件。


因为这时候spring容器还没被初始化，所以想要自己的扩展的生效，有以下三种方式：

在启动类中用springApplication.addInitializers(new TestApplicationContextInitializer())语句加入
配置文件配置context.initializer.classes=com.example.demo.TestApplicationContextInitializer
Spring SPI扩展，在spring.factories中加入org.springframework.context.ApplicationContextInitializer=com.example.demo.TestApplicationContextInitializer

 */
public class MyApplicationContextInitalizer implements ApplicationContextInitializer {
    @Override
    public void initialize(ConfigurableApplicationContext configurableApplicationContext) {

        ConfigurableEnvironment environment = configurableApplicationContext.getEnvironment();


        System.out.println("=======================扩展 项目启动前时-- MyApplicationContextInitalizer init =======================");
    }
}
